package com.topisv.tms.repository.work.ExceptionOrder;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.entity.work.ExceptionOrder.ExceptionBackItem;

/**
 * 异常单退回商品明细_DAO
 * @author ch
 *
 */
public abstract interface ExceptionBackItemDao extends PagingAndSortingRepository<ExceptionBackItem, Long>, JpaSpecificationExecutor<ExceptionBackItem>
{

	@Query("select t from ExceptionBackItem t where t.exceptionId=?")
	List<ExceptionBackItem> loadByExceptionId(Long exceptionId);

	@Query("select t from ExceptionBackItem t where t.exceptionId=?1 and t.errorFlag=?2 and sku=?3")
	ExceptionBackItem loadByCondition(Long exceptionId, String errorFlag, String sku);
	
	@Query("select t from ExceptionBackItem t where t.exceptionId=?1 and t.errorFlag=?2 and sku=?3 "
	    + "and (batchCode = ?4 or batchCode is null or batchCode = '') "
	    + "and (productDate = ?5 or productDate is null or productDate = '') "
	    + "and (expireDate = ?6 or expireDate is null or expireDate = '')")
    ExceptionBackItem loadByConditionNew(Long exceptionId, String errorFlag, String sku, String batchCode, 
        String productDate, String expireDate);

}